home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / jade-3.2.lha / jade-3.2 / man / jade.info-5 < prev    next >
Encoding:
GNU Info File  |  1994-10-16  |  48.5 KB  |  1,312 lines

  1. This is Info file jade.info, produced by Makeinfo-1.55 from the input
  2. file jade.texi.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Jade: (jade).            An editor for X11 and AmigaDOS
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This is Edition 1.3, last updated 7 October 1994, of `The Jade
  9. Manual', for Jade, Version 3.2.
  10.  
  11.    Jade is a text editor for X11 (on Unix) and the Amiga.
  12.  
  13.    Copyright 1993, 1994 John Harper.
  14.  
  15.    Permission is granted to make and distribute verbatim copies of this
  16. manual provided the copyright notice and this permission notice are
  17. preserved on all copies.
  18.  
  19.    Permission is granted to copy and distribute modified versions of
  20. this manual under the conditions for verbatim copying, provided that
  21. the entire resulting derived work is distributed under the terms of a
  22. permission notice identical to this one.
  23.  
  24. 
  25. File: jade.info,  Node: Control Structures,  Next: Variables,  Prev: Evaluation,  Up: Programming Jade
  26.  
  27. Control Structures
  28. ==================
  29.  
  30.    Control structures are special forms or macros which control which
  31. forms get evaluated, when they get evaluated and the number of times to
  32. evaluate them. This includes conditional structures, loops, etc...
  33.  
  34.    The simplest control structures are the sequencing structures; they
  35. are used to evaluate a list of forms in left to right order.
  36.  
  37. * Menu:
  38.  
  39. * Sequencing Structures::       Evaluating several forms in sequence
  40. * Conditional Structures::      Making decisions based on truth values
  41. * Looping Structures::          `while' loops
  42. * Non-Local Exits::             Exiting from several levels of evaluation
  43.  
  44. 
  45. File: jade.info,  Node: Sequencing Structures,  Next: Conditional Structures,  Up: Control Structures
  46.  
  47. Sequencing Structures
  48. ---------------------
  49.  
  50.    Each of the special forms in this section simply evaluates its
  51. argument forms in left-to-right order. The only difference is the
  52. result they return.
  53.  
  54.    The most widely used sequencing special form is `progn': it
  55. evaluates all its argument forms and returns the computed value of the
  56. last one. Many other control structures are said to perform an
  57. "implicit progn", this means that they call `progn' with a list of
  58. forms.
  59.  
  60.    `progn' in Lisp is nearly analogous to a `begin...end' block in
  61. Pascal; it is used in much the same places -- to allow you to evaluate
  62. a sequence of form where only one form was allowed (for example the
  63. true clause of an `if' structure).
  64.  
  65.  - Special Form: progn FORMS...
  66.      All of the FORMS are evaluated sequentially (from left-to-right),
  67.      the result of the last evaluated FORM is the return value of this
  68.      structure. If no arguments are given to `progn' it returns `nil'.
  69.  
  70.           (progn 'one (+ 1 1) "three")
  71.               => "three"
  72.           
  73.           (progn)
  74.               => nil
  75.  
  76.  - Special Form: prog1 FIRST FORMS...
  77.      This special form evaluates its FIRST form then performs an
  78.      implicit progn on the rest of its arguments. The result of this
  79.      structure is the computed value of the first form.
  80.  
  81.           (prog1 'one (+ 1 1) "three")
  82.               => one
  83.  
  84.  - Special Form: prog2 FIRST SECOND FORMS...
  85.      This is similar to `prog1' except that the evaluated value of its
  86.      SECOND form is returned.
  87.  
  88.      The FIRST form is evaluated, then its SECOND, then it performs an
  89.      implicit progn on the remaining arguments.
  90.  
  91.           (prog2 'one (+ 1 1) "three")
  92.               => 2
  93.  
  94. 
  95. File: jade.info,  Node: Conditional Structures,  Next: Looping Structures,  Prev: Sequencing Structures,  Up: Control Structures
  96.  
  97. Conditional Structures
  98. ----------------------
  99.  
  100.    Lisp provides a number of conditional constructs, the most complex of
  101. which (`cond') will take a list of conditions, the first of which is
  102. `t' then has its associated list of forms evaluated. Theoretically this
  103. is the only conditional special form necessary -- the rest could be
  104. implemented as macros.
  105.  
  106.  - Special Form: if CONDITION TRUE-FORM ELSE-FORMS...
  107.      The `if' construct is the nearest thing in Lisp to the
  108.      "if-then-else" construct found in most programming languages.
  109.  
  110.      First the CONDITION form is evaluated, if it returns `t' (not
  111.      `nil') the TRUE-FORM is evaluated and its result returned.
  112.      Otherwise the result of an implicit progn on the ELSE-FORMS is
  113.      returned. If there are no ELSE-FORMS `nil' is returned.
  114.  
  115.      Note that one of the TRUE-FORM or the ELSE-FORMS is completely
  116.      ignored -- it is not evaluated.
  117.  
  118.           (if (special-form-p 'if)
  119.               "`if' is a special form"
  120.             "`if' is not a special form")
  121.               => "`if' is a special form"
  122.  
  123.  - Special Form: when CONDITION TRUE-FORMS...
  124.      CONDITION is evaluated, if it is `t' the result of an implicit
  125.      progn on the TRUE-FORMS is returned, otherwise `nil' is returned.
  126.  
  127.           (when t
  128.             (message "Pointless")
  129.             'foo)
  130.               => foo
  131.  
  132.  - Special Form: unless CONDITION ELSE-FORMS...
  133.      This special forms first evaluates CONDITION, if its computed
  134.      value is not `nil' its value is returned. Otherwise the ELSE-FORMS
  135.      are evaluated sequentially, the value of the last is returned.
  136.  
  137.  - Special Form: cond CLAUSE...
  138.      The `cond' special form is used to choose between an arbitrary
  139.      number of conditions. Each CLAUSE is a list; its car is the
  140.      CONDITION the list which is the cdr of the CLAUSE is the
  141.      BODY-FORMS. This means that each CLAUSE looks something like:
  142.  
  143.           (CONDITION BODY-FORMS...)
  144.  
  145.      and a whole `cond' form looks like:
  146.  
  147.           (cond
  148.            (CONDITION-1 BODY-FORMS-1...)
  149.            (CONDITION-2 BODY-FORMS-2...)
  150.            ...)
  151.  
  152.      The CONDITION in each CLAUSE is evaluated in sequence
  153.      (CONDITION-1, then CONDITION-2, ...), the first one which
  154.      evaluates to a non-`nil' has an implicit progn performed on its
  155.      BODY-FORMS, the value of which is the value returned by the `cond'
  156.      form.
  157.  
  158.      If the true CONDITION has no BODY-FORMS the value returned by
  159.      `cond' is the value of the CONDITION. If none of the clauses has a
  160.      non-`nil' CONDITION the value of the `cond' is `nil'.
  161.  
  162.      Often you want a "default" clause; one which has its BODY-FORMS to
  163.      be evaluated if none of the other clauses are true. The way to do
  164.      this is to add a clause with a CONDITION of `t' and BODY-FORMS of
  165.      whatever you want the default action to be.
  166.  
  167.           (cond
  168.            ((stringp buffer-list))        ;Clause with no BODY-FORMS
  169.            ((consp buffer-list)
  170.             (setq x buffer-list)          ;Two BODY-FORMS
  171.             t)
  172.            (t                             ;Default clause
  173.             (error "`buffer-list' is corrupted!")))
  174.               => t
  175.  
  176.      All of the other conditionals can be written in terms of `cond',
  177.  
  178.           (if C T E...) == (cond (C T) (t E...))
  179.           
  180.           (when C T...) == (cond (C T...))
  181.           
  182.           (unless C E...) == (cond (E) (t E...))
  183.  
  184.    There are also a number of special forms which combine conditions
  185. together by the normal logical rules.
  186.  
  187.  - Special Form: or FORMS...
  188.      The first of the FORMS is evaluated, if it is non-`nil' its value
  189.      becomes the value of the `or' form and no more of `forms' are
  190.      evaluated. Otherwise this step is repeated for the next member of
  191.      FORMS.
  192.  
  193.      If all of the FORMS have been evaluated and none have a non-`nil'
  194.      value `nil' becomes the value of the `or' form.
  195.  
  196.      If there are no FORMS `nil' is returned.
  197.  
  198.           (or nil 1 nil (beep))           ;`(beep)' won't be evaluated
  199.               => 1
  200.  
  201.  - Special Form: and FORMS...
  202.      The first of the FORMS is evaluated. If it is `nil' no more of the
  203.      FORMS are evaluated and `nil' becomes the value of the `and'
  204.      structure. Otherwise the next member of FORMS is evaluated and its
  205.      value tested. If none of the FORMS are `nil' the computed value of
  206.      the last member of FORMS becomes the value of the `and' form.
  207.  
  208.           (and 1 2 nil (beep))            ;`(beep)' won't be evaluated
  209.               => nil
  210.           
  211.           (and 1 2 3)                     ;All forms are evaluated
  212.               => 3
  213.  
  214.  - Function: not OBJECT
  215.      This function inverts the boolean value of its argument. If OBJECT
  216.      is non-`nil', `nil' is returned, otherwise `t' is returned.
  217.  
  218.           (not nil)
  219.               => t
  220.           
  221.           (not t)
  222.               => nil
  223.           
  224.           (not 42)
  225.               => nil
  226.  
  227. 
  228. File: jade.info,  Node: Looping Structures,  Next: Non-Local Exits,  Prev: Conditional Structures,  Up: Control Structures
  229.  
  230. Looping Structures
  231. ------------------
  232.  
  233.    Jade's version of Lisp has only one structure for looping -- a
  234. "while" loop similar to those found in most programming languages.
  235.  
  236.  - Special Form: while CONDITION BODY-FORMS...
  237.      The CONDITION form is evaluated. If it is non-`nil' an implicit
  238.      progn is performed on the BODY-FORMS and the whole thing is
  239.      repeated again.
  240.  
  241.      This continues until the CONDITION form evaluates to `nil'. The
  242.      value of any `while' structure is `nil'.
  243.  
  244.      `while' can be recursively defined in terms of `when':
  245.  
  246.           (while C B ...)
  247.           ==
  248.           (when C (progn B ... (while C B ...)))
  249.  
  250.           ;; Step through a list X
  251.           (while X
  252.             ;; Do something with the current element, `(car X)'
  253.             (setq X (cdr X)))
  254.  
  255. 
  256. File: jade.info,  Node: Non-Local Exits,  Prev: Looping Structures,  Up: Control Structures
  257.  
  258. Non-Local Exits
  259. ---------------
  260.  
  261.    A "non-local exit" is a transfer of control from the current point
  262. of evaluation to a different point (somewhat similar to the
  263. much-maligned `goto' statement in some imperative languages).
  264.  
  265.    Non-local exits can either be used explicitly (`catch' and `throw')
  266. or implicitly (errors).
  267.  
  268. * Menu:
  269.  
  270. * Catch and Throw::             Programmed non-local exits
  271. * Function Exits::              Returning values from a function
  272. * Cleanup Forms::               Forms which will always be evaluated
  273. * Errors::                      Signalling that an error occurred
  274.  
  275. 
  276. File: jade.info,  Node: Catch and Throw,  Next: Function Exits,  Up: Non-Local Exits
  277.  
  278. Catch and Throw
  279. ...............
  280.  
  281.    The `catch' and `throw' structures are used to perform explicit
  282. transfers of control. First a `catch' form is used to setup a "tag",
  283. this acts like a label for the C language's `goto' statement. To
  284. transfer control a `throw' form is then used to transfer to the named
  285. tag. The tag is destroyed and the `catch' form exits with the value
  286. provided by the `throw'.
  287.  
  288.    In a program this looks like,
  289.  
  290.      (catch 'TAG
  291.        ;; Forms which may `throw' back to TAG
  292.        ...
  293.        (throw 'TAG VALUE)
  294.        ;; Control has now passed to the `catch',
  295.        ;; no more forms in this progn will be evaluated.
  296.        ...)
  297.          => VALUE
  298.  
  299. where TAG is the tag to be used (this is normally a symbol) and VALUE
  300. is the result of the `catch' form.
  301.  
  302.    When a throw actually happens all catches in scope are searched for
  303. one with a tag which is `eq' to the tag in the throw. If more than one
  304. exists the most-recent is chosen. Now that the catch has been located
  305. the environment is `wound-back' to the catch's position (i.e. local
  306. variables are unbound, cleanup forms removed, unused catches forgotten,
  307. etc...) and all Lisp constructs between the current point of control and
  308. the catch are exited.
  309.  
  310.    For example,
  311.  
  312.      (let
  313.          ((test 'outer))
  314.        (cons (catch 'foo
  315.                (let
  316.                    ((test 'inner))
  317.                  (throw 'foo test)
  318.                  (setq test 'unreachable)))  ;Never reached
  319.              test))
  320.          => (inner . outer)
  321.  
  322. when the throw executes the second binding of `test' is unwound and the
  323. first binding comes back into effect. For more details on variable
  324. binding see *Note Local Variables::.
  325.  
  326.    Note that catch tags are *dynamically* scoped, the thrower does not
  327. have to be within the same lexical scope (this means you can throw
  328. through functions).
  329.  
  330.  - Special Form: catch TAG BODY-FORMS...
  331.      This special form defines a catch tag which will be accessible
  332.      while the BODY-FORMS are being evaluated.
  333.  
  334.      TAG is evaluated and recorded as the tag for this catch. Next the
  335.      BODY-FORMS are evaluated as an implicit progn. The value of the
  336.      `catch' form is either the value of the progn, or, if a `throw'
  337.      happened, the value specified in the THROW form.
  338.  
  339.      Before exiting the tag installed by this form is removed.
  340.  
  341.  - Function: throw TAG &optional CATCH-VALUE
  342.      This function transfers the point of control to the catch form
  343.      with a tag which is `eq' to TAG. The value returned by this catch
  344.      form is either CATCH-VALUE or `nil' if CATCH-VALUE is undefined.
  345.  
  346.      If there is no catch with a tag of TAG an error is signalled and
  347.      the editor returns to the top-level of evaluation.
  348.  
  349. 
  350. File: jade.info,  Node: Function Exits,  Next: Cleanup Forms,  Prev: Catch and Throw,  Up: Non-Local Exits
  351.  
  352. Function Exits
  353. ..............
  354.  
  355.    It is often useful to be able to immediately return control from a
  356. function definition (like the C `return' statement). Jade's version of
  357. Lisp has the `return' function for this.
  358.  
  359.  - Function: return &optional VALUE
  360.      This function transfers control out of the most-recent
  361.      lambda-expression (i.e. a function or macro definition) so that
  362.      the result of the lambda- expression is VALUE.
  363.  
  364.           (funcall '(lambda () (return 'x) 'y))
  365.               => x
  366.  
  367.      The `'y' form is never evaluated since control is passed straight
  368.      from the `(return 'y)' form back to the `funcall' form.
  369.  
  370. 
  371. File: jade.info,  Node: Cleanup Forms,  Next: Errors,  Prev: Function Exits,  Up: Non-Local Exits
  372.  
  373. Cleanup Forms
  374. .............
  375.  
  376.    It is sometimes necessary to be sure that a certain form is *always*
  377. evaluated, even when a non-local exit would normally bypass that form.
  378. The `unwind-protect' special form is used to stop this happening.
  379.  
  380.  - Special Form: unwind-protect BODY-FORM CLEANUP-FORMS...
  381.      The BODY-FORM is evaluated, if it exits normally the CLEANUP-FORMS
  382.      are evaluated sequentially then the value which the BODY-FORM
  383.      returned becomes the value of the `unwind-protect' form. If the
  384.      BODY-FORM exits abnormally though (i.e. a non-local exit happened)
  385.      the CLEANUP-FORMS are evaluated anyway and the non-local exit
  386.      continues.
  387.  
  388.      One use of this is to ensure that an opened file is always closed,
  389.      for example,
  390.  
  391.           (catch 'foo
  392.             (unwind-protect
  393.                 (let
  394.                     ((temporary-file (open (tmp-file-name) "w")))
  395.                   ;; Use `temporary-file'
  396.                   (write temporary-file "A test\n")
  397.                   ;; Now force a non-local exit
  398.                   (throw 'foo))
  399.               ;; This is the CLEANUP-FORM it will *always*
  400.               ;; be evaluated no matter what happens.
  401.               (close temporary-file)))
  402.               => nil
  403.  
  404. 
  405. File: jade.info,  Node: Errors,  Prev: Cleanup Forms,  Up: Non-Local Exits
  406.  
  407. Errors
  408. ......
  409.  
  410.    Errors are a type of non-local exit; when a form can not be evaluated
  411. properly an error is normally "signalled". If an error-handler has been
  412. installed for that type of error control is unwound back to the handler
  413. and evaluation continues. If there is no suitable handler control is
  414. passed back to the event loop of the most-recent recursive edit and a
  415. suitable error message is printed.
  416.  
  417.  - Function: signal ERROR-SYMBOL DATA
  418.      Signals that an error has happened. ERROR-SYMBOL is a symbol
  419.      classifying the type of error, it should have a property
  420.      `error-message' (a string) which is the error message to be
  421.      printed.
  422.  
  423.      DATA is a list of objects which are relevant to the error -- they
  424.      will be made available to any error-handler or printed with the
  425.      error message otherwise.
  426.  
  427.           (signal 'void-value '(some-symbol))
  428.               error--> Value as variable is void: some-symbol
  429.  
  430.  - Variable: debug-on-error
  431.      This variable is consulted by the function `signal'. If its value
  432.      is either `t' or a list containing the ERROR-SYMBOL to `signal' as
  433.      one of its elements, the Lisp debugger is entered.  When the
  434.      debugger exits the error is signalled as normal.
  435.  
  436.    When you expect an error to occur and need to be able to regain
  437. control afterwards the `error-protect' form can be used.
  438.  
  439.  - Special Form: error-protect BODY-FORM ERROR-HANDLERS...
  440.      `error-protect' evaluates the BODY-FORM with error handlers in
  441.      place.
  442.  
  443.      Each of the ERROR-HANDLERS is a list whose car is a symbol
  444.      defining the type of error which this handler catches. The cdr of
  445.      the list is a list of forms to be evaluated sequentially when the
  446.      handler is invoked.
  447.  
  448.      While the forms of the error handler are being evaluated the
  449.      variable `error-info' is bound to the value `(ERROR-SYMBOL . DATA)'
  450.      (these were the arguments to the `signal' form which caused the
  451.      error).
  452.  
  453.      The special value, the symbol `error', in the car of one of the
  454.      ERROR-HANDLERS will catch *all* types of errors.
  455.  
  456.           (error-protect
  457.               (signal 'file-error '("File not found" "/tmp/foo"))
  458.             (file-error
  459.              error-info)
  460.             (error
  461.              (setq x z)))         ;Default handler
  462.               => (file-error "File not found" "/tmp/foo")
  463.  
  464. 
  465. File: jade.info,  Node: Variables,  Next: Functions,  Prev: Control Structures,  Up: Programming Jade
  466.  
  467. Variables
  468. =========
  469.  
  470.    In Lisp symbols are used to represent variables. Each symbol
  471. contains a slot which is used to contain the value of the symbol when
  472. it is used as a symbol.
  473.  
  474.    The normal way to obtain the current value of a variable is simply to
  475. evaluate the symbol it lives in (i.e. write the name of the variable in
  476. your program).
  477.  
  478.  - Function: symbol-value VARIABLE
  479.      This function returns the value of the symbol VARIABLE in the
  480.      current environment.
  481.  
  482. * Menu:
  483.  
  484. * Local Variables::             Creating temporary variables
  485. * Setting Variables::           Altering a variable's value
  486. * Scope and Extent::            Technical jargon
  487. * Buffer-Local Variables::      Variables with distinct values in
  488.                                   each buffer.
  489. * Void Variables::              Some variables have no values
  490. * Constant Variables::          Variables which may not be altered
  491. * Defining Variables::          How to define a variable before
  492.                                   using it
  493.  
  494. 
  495. File: jade.info,  Node: Local Variables,  Next: Setting Variables,  Up: Variables
  496.  
  497. Local Variables
  498. ---------------
  499.  
  500.    A "local variable" is a variable which has a temporary value while a
  501. program is executing, for example, when a function is called the
  502. variables which are the names of its arguments are temporarily bound (a
  503. "binding" is a particular instance of a local variable) to the values
  504. of the arguments passed to the function. When the function call exits
  505. its arguments are unbound and the previous definitions of the variables
  506. come back into view.
  507.  
  508.    Even if a variable has more than one binding still `active' only the
  509. most recent is visible -- there is absolutely no way the previous
  510. bindings can be accessed until the bindings are unbound one-by-one.
  511.  
  512.    A nice way of visualising variable binding is to think of each
  513. variable as a stack. When the variable is bound to, a new value is
  514. pushed onto the stack, when it is unbound the top of the stack is
  515. popped. Similarly when the stack is empty the value of the variable is
  516. void (*note Void Variables::.). Assigning a value to the variable
  517. (*note Setting Variables::.) overwrites the top value on the stack with
  518. a new value. When the value of the variable is required it is simply
  519. read from the top of the stack.
  520.  
  521.    Apart from function calls there are two special forms which perform
  522. variable binding (i.e. creating local variables), `let' and `let*'.
  523.  
  524.  - Special Form: let BINDINGS BODY-FORMS...
  525.      `let' creates new variable bindings as specified by the BINDINGS
  526.      argument then evaluates the BODY-FORMS in order. The variables are
  527.      then unbound to their state before this `let' form and the value
  528.      of the implicit progn of the BODY-FORMS becomes the value of the
  529.      `let' form.
  530.  
  531.      The BINDINGS argument is a list of the bindings to perform. Each
  532.      binding is either a symbol, in which case that variable is bound to
  533.      nil, or a list whose car is a symbol. The cdr of this list is a
  534.      list of forms which, when evaluated, give the value to bind the
  535.      variable to.
  536.  
  537.           (setq foo 42)
  538.               => 42
  539.           (let
  540.               ((foo (+ 1 2))
  541.                bar)
  542.             ;; Body forms
  543.             (setq foo (1+ foo))   ;This sets the new binding
  544.             (cons foo bar))
  545.               => (4 . nil)
  546.           foo
  547.               => 42        ;The original values is back
  548.  
  549.      Note that no variables are bound until all the new values have been
  550.      computed (unlike in `let*'). For example,
  551.  
  552.           (setq foo 42)
  553.               => 42
  554.           (let
  555.               ((foo 100)
  556.                (bar foo))
  557.             (cons foo bar))
  558.               => (100 . 42)
  559.  
  560.      Although `foo' is given a new binding this is not actually done
  561.      until all the new bindings have been computed, hence `bar' is
  562.      bound to the *old* value of `foo'.
  563.  
  564.  - Special Form: let* BINDINGS BODY-FORMS...
  565.      This special form is exactly the same as `let' except for one
  566.      important difference: the new bindings are installed *as they are
  567.      computed*.
  568.  
  569.      You can see the difference by comparing the following example with
  570.      the last example in the `let' documentation (above),
  571.  
  572.           (setq foo 42)
  573.               => 42
  574.           (let*                   ;Using `let*' this time
  575.               ((foo 100)
  576.                (bar foo))
  577.             (cons foo bar))
  578.               => (100 . 100)
  579.  
  580.      By the time the binding of `bar' is computed the new binding of
  581.      `foo' has already been installed.
  582.  
  583. 
  584. File: jade.info,  Node: Setting Variables,  Next: Scope and Extent,  Prev: Local Variables,  Up: Variables
  585.  
  586. Setting Variables
  587. -----------------
  588.  
  589.    "Setting" a variable means to overwrite its current value (that is,
  590. the value of its most recent binding) with a new one. The old value is
  591. irretrievably lost (unlike when a new value is bound to a variable,
  592. *note Local Variables::.).
  593.  
  594.  - Special Form: setq VARIABLE FORM ...
  595.      The special form `setq' is the usual method of altering the value
  596.      of a variable. Each VARIABLE is set to the result of evaluating its
  597.      corresponding FORM. The last value assigned becomes the value of
  598.      the `setq' form.
  599.  
  600.           (setq x 20 y (+ 2 3))
  601.               => 5
  602.  
  603.      In the above example the variable `x' is set to `20' and `y' is
  604.      set to the value of the form `(+ 2 3)' (5).
  605.  
  606.      When the variable is marked as being buffer-local (*note
  607.      Buffer-Local Variables::.) the current buffer's instance of the
  608.      variable is set.
  609.  
  610.  - Function: set VARIABLE NEW-VALUE
  611.      The value of the variable VARIABLE (a symbol) is set to NEW-VALUE
  612.      and the NEW-VALUE is returned.
  613.  
  614.      This function is used when the VARIABLE is unknown until run-time,
  615.      and therefore has to be computed from a form.
  616.  
  617.           (set 'foo 20)
  618.           ==
  619.           (setq foo 20)           ;`setq' means `set-quoted'
  620.               => 20
  621.  
  622. 
  623. File: jade.info,  Node: Scope and Extent,  Next: Buffer-Local Variables,  Prev: Setting Variables,  Up: Variables
  624.  
  625. Scope and Extent
  626. ----------------
  627.  
  628.    In Jade's version of Lisp all variables have "indefinite scope" and
  629. "dynamic extent". What this means is that references to variables may
  630. occur anywhere in a program (i.e. bindings established in one function
  631. are not only accessible within that function, that's lexical scope) and
  632. that references may occur at any point in the time between the binding
  633. being created and it being unbound.
  634.  
  635.    The combination of indefinite scope and dynamic extent is often
  636. termed "dynamic scope".
  637.  
  638.    As an aside, Lisp objects have "indefinite extent", meaning that the
  639. object will exist for as long as there is a possibility of it being
  640. referenced (and possibly longer -- until the garbage collector runs).
  641.  
  642.    Note that in Common Lisp only those variables declared `special' have
  643. indefinite scope and dynamic extent.
  644.  
  645.    Try not to abuse the dynamic scoping, although it is often very
  646. useful to be able to bind a variable in one function and use it in
  647. another this can be confusing if not controlled and documented properly.
  648.  
  649.    A quick example of the use of dynamic scope,
  650.  
  651.      (defun foo (x)
  652.        (let
  653.            ((foo-var (* x 20)))
  654.          (bar x)
  655.          ...
  656.      
  657.      (defun bar (y)
  658.        ;; Since this function is called from
  659.        ;; the function `foo' it can refer
  660.        ;; to any bindings which `foo' can.
  661.        (setq y (+ y foo-var))
  662.        ...
  663.  
  664. 
  665. File: jade.info,  Node: Buffer-Local Variables,  Next: Void Variables,  Prev: Scope and Extent,  Up: Variables
  666.  
  667. Buffer-Local Variables
  668. ----------------------
  669.  
  670.    It is often very useful to be able to give variables different
  671. values for different editor buffers -- most major modes need to record
  672. some buffer-specific information. Jade allows you to do this by giving a
  673. variable buffer-local bindings.
  674.  
  675.    There are two strengths of buffer-local variables: you can either
  676. give a variable a buffer-local value in a single buffer, with other
  677. buffers treating the variable as normal, or a variable can be marked as
  678. being *automatically* buffer-local, each time the variable is set the
  679. current buffer's value of the variable is updated.
  680.  
  681.    Each buffer maintains an alist of the symbols which have buffer-local
  682. values in the buffer and the actual values themselves, this alist may
  683. be read with the `buffer-variables' function.
  684.  
  685.    When the value of a variable is referenced (via the `symbol-value'
  686. function) the current buffer's alist of local values is examined for a
  687. binding of the variable being referenced; if one is found that is the
  688. value of the variable, otherwise the "default value" (the value stored
  689. in the symbol's value cell) is used.
  690.  
  691.    Setting a variable also searches for a buffer-local binding; if one
  692. exists its value is modified, not the default value. If the variable
  693. has previously been marked as being automatically buffer-local (by
  694. `make-variable-buffer-local') a buffer-local binding is automatically
  695. created if one doesn't already exist.
  696.  
  697.    Currently there is one main problem with buffer-local variables:
  698. they can't have temporary values bound to them (or rather, they can but
  699. I guarantee it won't work how you expect), so for the time being, don't
  700. try to bind local values (with `let' or `let*') to a buffer-local
  701. variable.
  702.  
  703.  - Function: make-local-variable SYMBOL
  704.      This function gives the variable SYMBOL a buffer-local binding in
  705.      the current buffer. The value of this binding will be the same as
  706.      the variable's default value.
  707.  
  708.      If SYMBOL already has a buffer-local value in this buffer nothing
  709.      happens.
  710.  
  711.      Returns SYMBOL.
  712.  
  713.  - Function: make-variable-buffer-local SYMBOL
  714.      This function marks the variable SYMBOL as being automatically
  715.      buffer-local.
  716.  
  717.      This means that any attempts at setting the value of SYMBOL will
  718.      actually set the current buffer's local value (if necessary a new
  719.      buffer-local binding will be created in the buffer).
  720.  
  721.      Returns SYMBOL.
  722.  
  723.           (make-variable-buffer-local 'buffer-modtime)
  724.               => buffer-modtime
  725.  
  726.  - Function: default-value SYMBOL
  727.      This function returns the default value of the variable SYMBOL.
  728.  
  729.           (setq foo 'default)
  730.               => default
  731.           (make-local-variable 'foo)      ;Create a value in this buffer
  732.               => foo
  733.           (setq foo 'local)
  734.               => local
  735.           foo
  736.               => local
  737.           (symbol-value 'foo)
  738.               => local
  739.           (default-value 'foo)
  740.               => default
  741.  
  742.  - Function: default-boundp SYMBOL
  743.      Returns `t' if the variable SYMBOL has a non-void default value.
  744.  
  745.  - Special Form: setq-default SYMBOL FORM ...
  746.      Similar to the `setq' special form except that the default value
  747.      of each VARIABLE is set. In non-buffer-local symbols there is no
  748.      difference between `setq' and `setq-default'.
  749.  
  750.  - Function: set-default SYMBOL NEW-VALUE
  751.      Sets the default value of the variable SYMBOL to NEW-VALUE, then
  752.      returns NEW-VALUE.
  753.  
  754.  - Function: kill-local-variable SYMBOL
  755.      This function removes the buffer-local binding of the variable
  756.      SYMBOL from the current buffer (if one exists) then returns SYMBOL.
  757.  
  758.  - Function: kill-all-local-variables
  759.      This function removes all the buffer-local bindings associated
  760.      with the current buffer. Subsequently, any buffer-local variables
  761.      referenced while this buffer is current will use their default
  762.      values.
  763.  
  764.    The usual way to define an automatically buffer-local variable is to
  765. use `defvar' and `make-variable-buffer-local', for example,
  766.  
  767.      (defvar my-local-variable DEFAULT-VALUE
  768.        "Doc string for `my-local-variable'.")
  769.      (make-variable-buffer-local 'my-local-variable)
  770.  
  771.    Note that if you want to reference the value of a buffer-local
  772. variable in a buffer other than the current buffer, use the
  773. `with-buffer' special form (*note The Current Buffer::.). For example,
  774. the form,
  775.  
  776.      (with-buffer OTHER-BUFFER SOME-VARIABLE)
  777.  
  778. will produce the value of the variable SOME-VARIABLE in the buffer
  779. OTHER-BUFFER.
  780.  
  781. 
  782. File: jade.info,  Node: Void Variables,  Next: Constant Variables,  Prev: Buffer-Local Variables,  Up: Variables
  783.  
  784. Void Variables
  785. --------------
  786.  
  787.    A variable which has no value is said to be "void", attempting to
  788. reference the value of such a symbol will result in an error. It is
  789. possible for the most recent binding of a variable to be void even
  790. though the inactive bindings may have values.
  791.  
  792.  - Function: boundp VARIABLE
  793.      Returns `t' if the symbol VARIABLE has a value, `nil' if its value
  794.      is void.
  795.  
  796.  - Function: makunbound VARIABLE
  797.      This function makes the current binding of the symbol VARIABLE be
  798.      void, then returns VARIABLE.
  799.  
  800.           (setq foo 42)
  801.               => 42
  802.           foo
  803.               => 42
  804.           (boundp 'foo)
  805.               => t
  806.           (makunbound 'foo)
  807.               => foo
  808.           (boundp 'foo)
  809.               => nil
  810.           foo
  811.               error--> Value as variable is void: foo
  812.  
  813. 
  814. File: jade.info,  Node: Constant Variables,  Next: Defining Variables,  Prev: Void Variables,  Up: Variables
  815.  
  816. Constant Variables
  817. ------------------
  818.  
  819.    In Lisp constants are represented by variables which have been
  820. marked as being read-only. Any attempt to alter the value of a constant
  821. results in an error.
  822.  
  823.    Two of the most commonly used constants are `nil' and `t'.
  824.  
  825.  - Function: set-const-variable VARIABLE &optional READ-WRITE
  826.      This function defines whether or not the value of the symbol
  827.      VARIABLE may be modified. If READ-WRITE is `nil' or undefined the
  828.      variable is marked to be constant, otherwise it's marked to be a
  829.      normal variable.  The value returned is VARIABLE.
  830.  
  831.  - Function: const-variable-p VARIABLE
  832.      Returns `t' if the value of the symbol VARIABLE may be altered,
  833.      `nil' otherwise.
  834.  
  835.    Constants may behave a bit strangely when you compile the program
  836. they are used in: the value of the constant is likely to be hardwired
  837. into the compiled functions it is used in, and the constant is unlikely
  838. to be `eq' to itself!
  839.  
  840.    The compiler assumes that constant is always the same, whenever it is
  841. evaluated. It may even be evaluated more than once. *Note Compiled
  842. Lisp::.
  843.  
  844.    The special form `defconst' can be used to define constants, see
  845. *Note Defining Variables::.
  846.  
  847. 
  848. File: jade.info,  Node: Defining Variables,  Prev: Constant Variables,  Up: Variables
  849.  
  850. Defining Variables
  851. ------------------
  852.  
  853.    The special forms `defvar' and `defconst' allow you to define the
  854. global variables which will be used in a program. This is entirely
  855. optional; it is highly recommended though.
  856.  
  857.  - Special Form: defvar VARIABLE FORM [DOC-STRING]
  858.      This special form defines a global variable, the symbol VARIABLE.
  859.      If the value of VARIABLE is void the FORM is evaluated and its
  860.      value is stored as the value of VARIABLE (note that the default
  861.      value is modified, never a buffer-local value).
  862.  
  863.      If the DOC-STRING argument is defined it is a string documenting
  864.      VARIABLE. This string is then stored as the symbol's
  865.      `variable-documentation' property and can be accessed by the
  866.      `describe-variable' function.
  867.  
  868.           (defvar my-variable '(x y)
  869.             "This variable is an example showing the usage of the `defvar'
  870.           special form.")
  871.               => my-variable
  872.  
  873.  - Special Form: defconst CONSTANT FORM [DOC-STRING]
  874.      `defconst' defines a constant, the symbol CONSTANT. Its value (in
  875.      the case of a buffer-local symbol, its default value) is set to the
  876.      result of evaluating FORM. Note that unlike `defvar' the value of
  877.      the symbol is *always* set, even if it already has a value.
  878.  
  879.      The DOC-STRING argument, if defined, is the documentation string
  880.      for the constant.
  881.  
  882.           (defconst the-answer 42
  883.             "An example constant.")
  884.               => the-answer
  885.  
  886.      *Note Constant Variables::.
  887.  
  888. 
  889. File: jade.info,  Node: Functions,  Next: Macros,  Prev: Variables,  Up: Programming Jade
  890.  
  891. Functions
  892. =========
  893.  
  894.    A "function" is a Lisp object which, when applied to a sequence of
  895. argument values, produces a value -- the function's "result". It may
  896. also produce side-effects. All Lisp functions return results -- there
  897. is nothing like a procedure in Pascal.
  898.  
  899.    Functions are the main building-block in Lisp programs, each program
  900. is usually a system of inter-related functions.
  901.  
  902.    There are two types of function: "primitive functions" are functions
  903. written in the C language, these are sometimes called built-in
  904. functions, the object containing the C code itself is called a "subr".
  905. All other functions are written in Lisp.
  906.  
  907.  - Function: functionp OBJECT
  908.      Returns `t' if OBJECT is a function (i.e. it can be used as the
  909.      function argument of `funcall'.
  910.  
  911.           (functionp 'set)
  912.               => t
  913.           
  914.           (functionp 'setq)
  915.               => nil
  916.           
  917.           (functionp #'(lambda (x) (+ x 2)))
  918.              => t
  919.  
  920. * Menu:
  921.  
  922. * Lambda Expressions::          Structure of a function object
  923. * Named Functions::             Functions can be named by symbols,
  924. * Anonymous Functions::         Or they can be un-named
  925. * Predicate Functions::         Functions which return boolean values
  926. * Defining Functions::          How to write a function definition
  927. * Calling Functions::           Functions can be called by hand
  928. * Mapping Functions::           Map a function to the elements of a list
  929.  
  930. 
  931. File: jade.info,  Node: Lambda Expressions,  Next: Named Functions,  Up: Functions
  932.  
  933. Lambda Expressions
  934. ------------------
  935.  
  936.    "Lambda expressions" are used to create an object of type function
  937. from other Lisp objects, it is a list whose first element is the symbol
  938. `lambda'. All functions written in Lisp (as opposed to the primitive
  939. functions in C) are represented by a lambda expression.
  940.  
  941.    Note that a lambda expression is *not* an expression, evaluating a
  942. lambda expression will give an error (unless there is a function called
  943. `lambda').
  944.  
  945.    The format of a lambda expression is:
  946.  
  947.      (lambda LAMBDA-LIST [DOC] [INTERACTIVE-DECLARATION] BODY-FORMS... )
  948.  
  949. Where LAMBDA-LIST is the argument specification of the function, DOC is
  950. an optional documentation string, INTERACTIVE-DECLARATION is only
  951. required by editor commands (*note Commands::.) and the BODY-FORMS is
  952. the actual function code (when the function is called each form is
  953. evaluated in sequence, the last form's value is the result returned by
  954. the function).
  955.  
  956.    The LAMBDA-LIST is a list, it defines how the argument values
  957. applied to the function are bound to local variables which represent
  958. the arguments within the function. At its simplest it is simply a list
  959. of symbols, each symbol will have the corresponding argument value
  960. bound to it. For example, the lambda list,
  961.  
  962.      (lambda (x y) (+ x y))
  963.  
  964. takes two arguments, `x' and `y'. When this function is called with two
  965. arguments the first will be bound to `x' and the second to `y' (then
  966. the function will return their sum).
  967.  
  968.    To complicate matters there are several "lambda-list keywords" which
  969. modify the meaning of symbols in the lambda-list. Each keyword is a
  970. symbol whose name begins with an ampersand, they are:
  971.  
  972. `&optional'
  973.      All the variables following this keyword are considered "optional"
  974.      (all variables before the first keyword are "required": an error
  975.      will be signalled if a required argument is undefined in a
  976.      function call). If an optional argument is undefined it will
  977.      simply be given the value `nil'.
  978.  
  979.      Note that optional arguments must be specified if a later optional
  980.      argument is also specified. Use `nil' to explicitly show that an
  981.      optional argument is undefined.
  982.  
  983.      For example, if a function `foo' takes two optional arguments and
  984.      you want to call it with only the second argument defined, the
  985.      first argument must be specified as `nil' to ensure that the
  986.      correct argument value is bound to the correct variable.
  987.  
  988.           (defun foo (&optional arg-1 arg-2)
  989.             ...
  990.           
  991.           (foo nil arg-2-value)   ;Leave the first argument undefined
  992.  
  993. `&rest'
  994.      The `&rest' keyword allows a variable number of arguments to be
  995.      applied to a function, all the argument values which have not been
  996.      bound to argument variables are simply consed into a list and bound
  997.      to the variable after the `&rest' keyword. For example, in,
  998.  
  999.           (lambda (x &rest y) ...)
  1000.  
  1001.      the first argument, `x', is required. Any other arguments applied
  1002.      to this function are made into a list and this list is bound to the
  1003.      `y' variable.
  1004.  
  1005.    When a function represented by a lambda-list is called the first
  1006. thing that happens is to bind the argument values to the argument
  1007. variables. The LAMBDA-LIST and the list of argument values applied to
  1008. the function are worked through in parallel. Any required arguments
  1009. which are left undefined when the end of the argument values has been
  1010. reached causes an error.
  1011.  
  1012.    After the arguments have been processed the BODY-FORMS are evaluated
  1013. by an implicit progn, the value of which becomes the value of the
  1014. function call. Finally, all argument variables are unbound and control
  1015. passes back to the caller.
  1016.  
  1017. 
  1018. File: jade.info,  Node: Named Functions,  Next: Anonymous Functions,  Prev: Lambda Expressions,  Up: Functions
  1019.  
  1020. Named Functions
  1021. ---------------
  1022.  
  1023.    Functions are normally associated with symbols, the name of the
  1024. symbol being the same as the name of its associated function. Each
  1025. symbol has a special function cell (this is totally separate from the
  1026. symbol's value as a variable -- variables and functions may have the
  1027. same name without any problems occurring) which is used to store the
  1028. function's definition, either a lambda expression (*note Lambda
  1029. Expressions::.) or a subr (C code) object.
  1030.  
  1031.    The evaluator knows to indirect through the function value of a
  1032. symbol in any function call (*note Function Call Forms::.) so the
  1033. normal way to call a function is simply write its name as the first
  1034. element in a list, any arguments making up the other elements in the
  1035. list.  *Note List Forms::.
  1036.  
  1037.    The functions and special forms which take functions as their
  1038. arguments (i.e. `funcall') can also take symbols. For example,
  1039.  
  1040.      (funcall 'message "An example")
  1041.      ==
  1042.      (message "An example")
  1043.  
  1044.  - Function: symbol-function SYMBOL
  1045.      Returns the value of the function cell in the symbol SYMBOL.
  1046.  
  1047.           (symbol-function 'symbol-function)
  1048.               => #<subr symbol-function>
  1049.  
  1050.  - Function: fboundp SYMBOL
  1051.      This function returns `t' if the symbol SYMBOL has a non-void
  1052.      value in its function cell, `nil' otherwise.
  1053.  
  1054.           (fboundp 'setq)
  1055.               => t
  1056.  
  1057.  - Function: fset SYMBOL NEW-VALUE
  1058.      Sets the value of the function cell in the symbol SYMBOL to
  1059.      NEW-VALUE, then returns NEW-VALUE.
  1060.  
  1061.      This function is rarely used, see *Note Defining Functions::.
  1062.  
  1063.  - Function: fmakunbound SYMBOL
  1064.      This function makes the value of the function cell in SYMBOL void,
  1065.      then returns SYMBOL.
  1066.  
  1067. 
  1068. File: jade.info,  Node: Anonymous Functions,  Next: Predicate Functions,  Prev: Named Functions,  Up: Functions
  1069.  
  1070. Anonymous Functions
  1071. -------------------
  1072.  
  1073.    When giving function names as arguments to functions it is useful to
  1074. give an actual function *definition* (i.e. a lambda expression) instead
  1075. of the name of a function.
  1076.  
  1077.    In Lisp, unlike most other programming languages, functions have no
  1078. inherent name. As seen in the last section named-functions are created
  1079. by storing a function in a special slot of a symbol, if you want, a
  1080. function can have many different names: simply store the function in
  1081. many different symbols!
  1082.  
  1083.    So, when you want to pass a function as an argument there is the
  1084. option of just writing down its definition. This is especially useful
  1085. with functions like `mapcar' and `delete-if'. For example, the
  1086. following form removes all elements from the LIST which are even and
  1087. greater than 20.
  1088.  
  1089.      (setq LIST (delete-if #'(lambda (x)
  1090.                                      (and (zerop (% x 2))
  1091.                                           (> x 20)))
  1092.                                  LIST))
  1093.  
  1094.    The lambda expression is very simple, it combines two predicates
  1095. applied to its argument.
  1096.  
  1097.    Note that the function definition is quoted by `#'', not the normal
  1098. `''. This is a special shortcut for the `function' special form (like
  1099. `'' is a shortcut to `quote'). In general, `#'X' is expanded by the
  1100. Lisp reader to `(function X)'.
  1101.  
  1102.  - Special Form: function ARG
  1103.      This special form is nearly identical to the `quote' form, it
  1104.      always returns its argument without evaluating it. The difference
  1105.      is that the Lisp compiler knows to compile the ARG into a byte-code
  1106.      form (unless ARG is a symbol in which case it is not compiled).
  1107.  
  1108.      What this means is when you have to quote a function, use the `#''
  1109.      syntax.
  1110.  
  1111. 
  1112. File: jade.info,  Node: Predicate Functions,  Next: Defining Functions,  Prev: Anonymous Functions,  Up: Functions
  1113.  
  1114. Predicate Functions
  1115. -------------------
  1116.  
  1117.    In Lisp, a function which returns a boolean `true' or boolean `false'
  1118. value is called a "predicate". As is the convention in Lisp a value of
  1119. `nil' means false, anything else means true. The symbol `t' is often
  1120. used to represent a true value (in fact, sometimes the symbol `t'
  1121. should be read as *any* non-`nil' value).
  1122.  
  1123.    Another Lisp convention is that the names of predicate functions
  1124. should be the concept the predicate is testing for and either `p' or
  1125. `-p'.
  1126.  
  1127.    The `p' variant is used when the concept name does not contain any
  1128. hyphens.
  1129.  
  1130.    For example a predicate to test for the concept "const-variable" (a
  1131. variable which has a constant value, *note Constant Variables::.) would
  1132. be called `const-variable-p'. On the other hand a predicate to test for
  1133. the concept "buffer" (a Lisp object which is a buffer) would be called
  1134. `bufferp'.
  1135.  
  1136. 
  1137. File: jade.info,  Node: Defining Functions,  Next: Calling Functions,  Prev: Predicate Functions,  Up: Functions
  1138.  
  1139. Defining Functions
  1140. ------------------
  1141.  
  1142.    Named functions are normally defined by the `defun' special form.
  1143.  
  1144.  - Special Form: defun NAME LAMBDA-LIST BODY-FORMS...
  1145.      `defun' initialises the function definition of the symbol NAME to
  1146.      the lambda expression resulting from the concatenation of the
  1147.      symbol `lambda', LAMBDA-LIST and the BODY-FORMS. So,
  1148.  
  1149.           (defun foo (x y)
  1150.             ...
  1151.           ==
  1152.           (fset 'foo #'(lambda (x y)
  1153.                          ...
  1154.  
  1155.      The BODY-FORMS may contain a documentation string for the function
  1156.      as its first form and an interactive calling specification as its
  1157.      first (if there is no doc-string) or second form if the function
  1158.      may be called interactively by the user (*note Commands::.).
  1159.  
  1160.    An example function definition (actually a command) taken from Jade's
  1161. source is,
  1162.  
  1163.      (defun upcase-word (count)
  1164.        "Makes the next COUNT words from the cursor upper-case."
  1165.        (interactive "p")
  1166.        (let
  1167.            ((pos (forward-word count)))
  1168.          (upcase-area (cursor-pos) pos)
  1169.          (goto-char pos)))
  1170.  
  1171. 
  1172. File: jade.info,  Node: Calling Functions,  Next: Mapping Functions,  Prev: Defining Functions,  Up: Functions
  1173.  
  1174. Calling Functions
  1175. -----------------
  1176.  
  1177.    Most of the time function calls are done by the evaluator when it
  1178. detects a function call form (*note List Forms::.); when the function
  1179. to be called is not known until run-time it is easier to use a special
  1180. function to call the function directly than create a custom form to
  1181. apply to the `eval' function.
  1182.  
  1183.  - Function: funcall FUNCTION &rest ARGS
  1184.      Applies the argument values ARGS to the function FUNCTION, then
  1185.      returns its result.
  1186.  
  1187.      Note that the argument values ARGS are *not* evaluated again. This
  1188.      also means that `funcall' can *not* be used to call macros or
  1189.      special forms -- they would need the unevaluated versions of ARGS,
  1190.      which are not available to `funcall'.
  1191.  
  1192.           (funcall '+ 1 2 3)
  1193.               => 6
  1194.  
  1195.  - Function: apply FUNCTION &rest ARGS
  1196.      Similar to `funcall' except that the last of its arguments is a
  1197.      *list* of arguments which are appended to the other members of
  1198.      ARGS to form the list of argument values to apply to the function
  1199.      FUNCTION.
  1200.  
  1201.      Constructs a list of arguments to apply to the function FUNCTION
  1202.      from ARGS.
  1203.  
  1204. 
  1205. File: jade.info,  Node: Mapping Functions,  Prev: Calling Functions,  Up: Functions
  1206.  
  1207. Mapping Functions
  1208. -----------------
  1209.  
  1210.    A "mapping function" applies a function to each of a collection of
  1211. objects. Jade currently has two mapping functions, `mapcar' and `mapc'.
  1212.  
  1213.  - Function: mapcar FUNCTION LIST
  1214.      Each element in the list LIST is individually applied to the
  1215.      function FUNCTION. The values returned are made into a new list
  1216.      which is returned.
  1217.  
  1218.      The FUNCTION should be able to be called with one argument.
  1219.  
  1220.           (mapcar '1+ '(1 2 3 4 5))
  1221.               => (2 3 4 5 6)
  1222.  
  1223.  - Function: mapc FUNCTION LIST
  1224.      Similar to `mapcar' except that the values returned when each
  1225.      element is applied to the function FUNCTION are discarded. The
  1226.      value returned is LIST.
  1227.  
  1228.      This function is generally used where the side effects of calling
  1229.      the function are the important thing, not the results.
  1230.  
  1231.    The two following functions are also mapping functions of a sort.
  1232. They are variants of the `delete' function (*note Modifying Lists::.)
  1233. and use predicate functions to classify the elements of the list which
  1234. are to be deleted.
  1235.  
  1236.  - Function: delete-if PREDICATE LIST
  1237.      This function is a variant of the `delete' function. Instead of
  1238.      comparing each element of LIST with a specified object, each
  1239.      element of LIST is applied to the predicate function PREDICATE.
  1240.      If it returns `t' (i.e. not `nil') then the element is
  1241.      destructively removed from LIST.
  1242.  
  1243.           (delete-if 'stringp '(1 "foo" 2 "bar" 3 "baz"))
  1244.               => (1 2 3)
  1245.  
  1246.  - Function: delete-if-not PREDICATE LIST
  1247.      This function does the inverse of `delete-if'. It applies PREDICATE
  1248.      to each element of LIST, if it returns `nil' then the element is
  1249.      destructively removed from the list.
  1250.  
  1251.           (delete-if-not 'stringp '(1 "foo" 2 "bar" 3 "baz"))
  1252.               => ("foo" "bar" "baz")
  1253.  
  1254. 
  1255. File: jade.info,  Node: Macros,  Next: Streams,  Prev: Functions,  Up: Programming Jade
  1256.  
  1257. Macros
  1258. ======
  1259.  
  1260.    "Macros" are used to extend the Lisp language, they are basically a
  1261. function which instead of returning its value, return a new form which
  1262. will produce the macro call's value when evaluated.
  1263.  
  1264.    When a function being compiled calls a macro the macro is expanded
  1265. immediately and the resultant form is open-coded into the compiler's
  1266. output.
  1267.  
  1268. * Menu:
  1269.  
  1270. * Defining Macros::             Macros are defined like functions
  1271. * Macro Expansion::             How macros are used by the evaluator
  1272. * Compiling Macros::            The compiler expands macros at compile-
  1273.                                   time.
  1274.  
  1275. 
  1276. File: jade.info,  Node: Defining Macros,  Next: Macro Expansion,  Up: Macros
  1277.  
  1278. Defining Macros
  1279. ---------------
  1280.  
  1281.    Macros are defined in the same style as functions, the only
  1282. difference is the name of the special form used to define them.
  1283.  
  1284.    A macro object is a list whose car is the symbol `macro', its cdr is
  1285. the function which creates the expansion of the macro when applied to
  1286. the macro calls unevaluated arguments.
  1287.  
  1288.  - Special Form: defmacro NAME LAMBDA-LIST BODY-FORMS...
  1289.      Defines the macro stored in the function cell of the symbol NAME.
  1290.      lAMBDA-LIST is the lambda-list specifying the arguments to the
  1291.      macro (*note Lambda Expressions::.) and BODY-FORMS are the forms
  1292.      evaluated when the macro is expanded. The first of BODY-FORMS may
  1293.      be a documentation string describing the macro's use.
  1294.  
  1295.    Here is a simple macro definition, it is a possible definition for
  1296. the `when' construct (which might even be useful if `when' wasn't
  1297. already defined as a special form...),
  1298.  
  1299.      (defmacro when (condition &rest body)
  1300.        "Evaluates CONDITION, if it's non-`nil' evaluates the BODY
  1301.      forms."
  1302.        (list 'if condition (cons 'progn body)))
  1303.  
  1304. When a form of the type `(when C B ...)' is evaluated the macro
  1305. definition of `when' expands to the form `(if C (progn B ...))' which
  1306. is then evaluated to perform my when-construct.
  1307.  
  1308.    When you define a macro ensure that the forms which produce the
  1309. expansion have no side effects; it would fail spectacularly when you
  1310. attempt to compile your program!
  1311.  
  1312.